<template>
  <div class="change_admin">
    <el-dialog
      :title="title"
      class="gl_dialog_TitleLine"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="880px"
    >
      <el-form ref="form" class="gl_form_mini" :model="testVO" label-width="120px" label-position="right" style="padding-right: 30px;" :rules="TestVO_Rules">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="编码" prop="type">
              <el-input v-model="testVO.code" size="mini" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="名称" prop="name">
              <el-input v-model="testVO.name" size="mini" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="角色" prop="name">
              <el-input v-model="testVO.role" size="mini" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型" prop="name">
              <el-input v-model="testVO.type" size="mini" clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="close()">取消</el-button>
        <el-button type="primary" size="mini" @click="saveNew('form')">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { TestVO } from '@/lib/form/configuration.js';
import { TestVO_Rules } from '@/lib/validate/configuration/index.js';
export default {
  name: 'Account',
  data() {
    return {
      // formData: {
      //   type: '',
      //   name: '',
      //   address: ''
      // },
      testVO: new TestVO(),
      TestVO_Rules: new TestVO_Rules(),
      title: '',
      dialogVisible: false
    };
  },
  methods: {
    onSubmit() {
      console.log('submit!');
    },
    open(row) {
      if (row === 'add') {
        this.title = '新增';
        this.testVO = new TestVO();
      } else {
        this.title = '编辑';
        this.testVO = JSON.parse(JSON.stringify(row));
      }
      this.dialogVisible = true;
      console.log(row);
      // this.form = row;
    },
    close() {
      this.dialogVisible = false;
      this.$refs.form.resetFields();
    },
    // 点击确定添加
    saveNew(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.title === '新增') {
            console.log(this.formData);
            this.$emit('pushTabelData', this.testVO);
            this.$refs[formName].resetFields();
          } else {
            console.log(this.testVO);
          }
        } else {
          return false;
        }
      });
    }
  }
};
</script>

